//
//  WFNavigationController.m
//  WildFireChat
//
//  Created by 0000 on 2024/5/14.
//  Copyright © 2024 WildFireChat. All rights reserved.
//

#import "WFNavigationController.h"
#define BarBackgroundFrame @"_UIBarBackground"
#import "YGExtendChain.h"

@interface WFNavigationController ()
@property (nonatomic, strong) UIView *barBackground;

@end

@implementation WFNavigationController
 
#pragma mark --- life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    
//    BOOL isPhoneX = NO;

    
 
//    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"自定义标题" style:UIBarButtonItemStylePlain target:nil action:nil];
//    self.navigationItem.backBarButtonItem = backButton;

    
//    UIBarButtonItem *item = [[UIBarButtonItem alloc] init];
//    item.title = @" ";
//    self.navigationItem.backBarButtonItem = item;
//    
//    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@" " style:UIBarButtonItemStylePlain target:nil action:nil];
//    self.navigationItem.backBarButtonItem = backButton;
//    
}
 
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
//    NSLog(@"%@---",self.navigationBar.subviews);

//    self.navigationItem.backBarButtonItem.title = @"" ;
    if (@available(iOS 11.0, *)) {
//        self.navigationController.navigationItem.backButtonTitle = @"" ;
    } else {
        // Fallback on earlier versions
    }
    
//    UIBarButtonItem *item = [[UIBarButtonItem alloc] init];
//    item.title = @" " ;
//    self.navigationItem.backBarButtonItem = item;
    
    
}
 
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    UIImageView* blackLineImageView = [self findHairlineImageViewUnder:self.navigationBar];
    if (blackLineImageView) {
        blackLineImageView.hidden = YES;
////        blackLineImageView.image = [UIImage imageWithColor:[UIColor clearColor]];
//
//    }
//    NSLog(@"%@---",self.navigationController.navigationBar.subviews);
//    NSLog(@"%@--blackLineImageView-",self.navigationBar.subviews);
//    for (UIView *view in self.navigationBar.subviews) {
//        if ([view isKindOfClass:NSClassFromString(@"_UIBarBackground")]) {
//            _barBackground = view;
//            // 注册监听
//         }
    }
}
- (UIImageView *)findHairlineImageViewUnder:(UIView *)view
{
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0)
    {
        return (UIImageView *)view;
    }
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    return nil;
}

//- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
//    // 上下文
//    if (context == BarBackgroundFrame) {
//        CGFloat systemVersion = [UIDevice currentDevice].systemVersion.floatValue;
//        if (_barBackground &&
//            systemVersion >= 11.0 &&
//            _barBackground.frame.size.height == 44) {
//            CGRect frame = _barBackground.frame;
//            frame.origin.y = -20;
//            frame.size.height = 64;
//            _barBackground.frame = frame;
//            NSLog(@"修改后的Frame: %@",NSStringFromCGRect(_barBackground.frame));
//        }
//    }
//}
//push时，隐藏底部tabbar
//- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
//    if (self.viewControllers.count > 0) {
//        [viewController setHidesBottomBarWhenPushed:YES];
//    }
//    [super pushViewController:viewController animated:YES];
//}
//- (void)back{
//    [self popViewControllerAnimated:YES];
//}
//- (void)dealloc {
//    [_barBackground removeObserver:self forKeyPath:@"frame" context:( void *)BarBackgroundFrame];
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
